<%--
  Created by IntelliJ IDEA.
  User: 86186
  Date: 2022/3/18
  Time: 15:38
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html xmlns="http://www.w3.org/1999/xhtml">
	
<head>
    <title>学员信息</title>
</head>
<body>
<%--导入页面上部分--%>
<%@include file="common/top.jsp"%>
<%--导入页面左部分--%>
<%@include file="common/left.jsp"%>
<%--导入页面所有css样式和jQuery--%>
<%@include file="common/model.jsp"%>
<div id="wrapper">
<div id="page-wrapper" >
    <div id="page-inner">
        <div class="row">
            <div class="col-md-12">
                <h1 class="page-header">
                   某某学校 <small>学员信息表</small>
                </h1>
            </div>
        </div>
        <!-- /. ROW  -->

        <div class="row">
            <div class="col-md-12">
                <!-- Advanced Tables -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <a class="btn" href="${pageContext.request.contextPath}/student.do?action=showadd">新增学员</a>
                    </div>
                    <div class="panel-body">
                        <div id="find_wrapper" class="dataTables_wrapper form-inline" role="grid">
                            <form method="post">
                                <label for="searchStudentNo">学号：</label><input type="search" name="studentNo" id="searchStudentNo" value="${requestScope.searchStudent!=null?requestScope.searchStudent.studentNo:""}">
                                <label for="searchStudentName">姓名：</label><input type="search" name="studentName" id="searchStudentName" value="${requestScope.searchStudent!=null?requestScope.searchStudent.studentName:""}">
                                <button type="button" class="btn btn-default">搜索</button>
                            </form>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                <tr>
                                    <th>学号</th>
                                    <th>姓名</th>
                                    <th>性别</th>
                                    <th>年级</th>
                                    <th>联系电话</th>
                                    <th>详情</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach items="${requestScope.students}" var="student">
                                    <tr class="odd gradeX"studentno=${student.studentNo}>
                                        <td>${student.studentNo}</td>
                                        <td>${student.studentName}</td>
                                        <td>${student.sex}</td>
                                        <td>${student.gradeId}</td>
                                        <td class="center">${student.phone}</td>
                                        <td class="center">
                                            <a href="${pageContext.request.contextPath}/student.do?action=demand&studentno=${student.studentNo}">详情</a>
                                            <a href="${pageContext.request.contextPath}/student.do?action=modifyview&studentno=${student.studentNo}">修改</a>
                                            <a href="javascript:">删除</a>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                            <%--分页--%>
                            <div class="row">
                                <div class="col-sm-6">
                                    <div class="dataTables_info" id="dataTables-example_info" role="alert" aria-live="polite" aria-relevant="all">
                                        Showing 1 to 10 of 57 entries
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
                                        <ul class="pagination">
                                            <li class="paginate_button previous disabled" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">
                                                <a href="#">Previous</a>
                                            </li>
                                            <li class="paginate_button active" aria-controls="dataTables-example" tabindex="0">
                                                <a href="#">1</a>
                                            </li>
                                            <li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
                                                <a href="#">2</a>
                                            </li>
                                            <li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
                                                <a href="#">3</a>
                                            </li>
                                            <li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
                                                <a href="#">4</a>
                                            </li>
                                            <li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
                                                <a href="#">5</a>
                                            </li>
                                            <li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
                                                <a href="#">6</a>
                                            </li>
                                            <li class="paginate_button next" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_next">
                                                <a href="#">Next</a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!--End Advanced Tables -->
            </div>

        </div>
            </div>
        </div>
</div>
</body>

<script type="text/javascript">
    //删除确认方法
    $(function(){
        $("#dataTables-example tbody tr td a:nth-of-type(3)").click(function(){

            var tempId = $(this).parents("tr").attr("studentno");
            var choice = window.confirm("确定要删除该学员吗?"+tempId);
            if (choice){
                alert("a");
                location="${pageContext.request.contextPath}/student.do?action=delete&studentno="+tempId;
            }
        })
    })

    //搜索异步刷新方法
    $(function (){
        $("#find_wrapper>form>button" ).click(function(){
            // alert("a");
            $.post(
                "${pageContext.request.contextPath}/student.do?action=search",
                $("#find_wrapper>form").serialize(),
                accept,
                "JSON"
            )
            function accept(data){
                $("#dataTables-example>tbody").empty();
                $(data).each(function (){
                    let $tr = $("<tr class=\"odd gradeX\" studentno=\""+this.studentNo+"\"></tr>");
                        $tr.append("<td>"+this.studentNo+"</td>")
                        $tr.append("<td>"+this.studentName+"</td>")
                        $tr.append("<td>"+this.sex+"</td>")
                        $tr.append("<td>"+this.gradeId+"</td>")
                        $tr.append("<td>"+this.phone+"</td>")
                    let $td = $("<td class=\"center\"></td>")
                        $td.append($("<a href=\"${pageContext.request.contextPath}/student.do?action=demand&studentno="+this.studentNo+"\">详情</a>"))
                        $td.append(" &nbsp;")
                        $td.append($("<a href=\"${pageContext.request.contextPath}/student.do?action=modifyview&studentno="+this.studentNo+"\">修改</a>"))
                        $td.append(" &nbsp;")
                        $td.append($("<a href=\"javascript:\">删除</a>"))
                    $tr.append($td)
                    $("#dataTables-example").append($tr)
                })
            }
        })
    })
</script>
    </html>
